package org.colin.utils;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.colin.code.BaseResponseCode;
import org.colin.code.ResponseCodeInterface;
/**
 * @Description: DataResult
 * @ClassName: DataResult
 * @Author: wujiangbo(QQ : 1134135987)
 * @Date: 2020/2/16 21:12
 * @Version: 1.1.0
 */
@Data
public class DataResult<T> {

    /**
     * 请求响应code，0为成功 其他为失败
     */
    @ApiModelProperty(value = "请求响应code，0为成功 其他为失败", name = "code")
    private int code;

    /**
     * 响应异常码详细信息
     */
    @ApiModelProperty(value = "响应异常码详细信息", name = "msg")
    private String msg;

    /**
     * 响应内容 ， code 0 时为 返回 数据
     */
    @ApiModelProperty(value = "需要返回的数据", name = "data")
    private T data;

    public DataResult(int code, T data) {
        this.code = code;
        this.data = data;
        this.msg = null;
    }

    public DataResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public DataResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = null;
    }

    public DataResult() {
        this.code = BaseResponseCode.SUCCESS.getCode();
        this.msg = BaseResponseCode.SUCCESS.getMsg();
        this.data = null;
    }

    public DataResult(T data) {
        this.data = data;
        this.code = BaseResponseCode.SUCCESS.getCode();
        this.msg = BaseResponseCode.SUCCESS.getMsg();
    }

    public DataResult(ResponseCodeInterface responseCodeInterface) {
        this.data = null;
        this.code = responseCodeInterface.getCode();
        this.msg = responseCodeInterface.getMsg();
    }

    public DataResult(ResponseCodeInterface responseCodeInterface, T data) {
        this.data = data;
        this.code = responseCodeInterface.getCode();
        this.msg = responseCodeInterface.getMsg();
    }

    /**
     * 操作成功 data为null
     *
     * @param
     * @return com.xh.lesson.utils.DataResult<T>
     * @throws
     * @Author: wujiangbo
     * @CreateDate: 2019/9/4 23:08
     * @UpdateUser:
     * @UpdateDate: 2019/9/4 23:08
     * @Version: 0.0.1
     */
    public static <T> DataResult success() {
        return new <T>DataResult();
    }

    /**
     * 操作成功 data 不为null
     *
     * @param data
     * @return com.xh.lesson.utils.DataResult<T>
     * @throws
     * @Author: wujiangbo
     * @CreateDate: 2019/9/4 23:09
     * @UpdateUser:
     * @UpdateDate: 2019/9/4 23:09
     * @Version: 0.0.1
     */
    public static <T> DataResult success(T data) {
        return new <T>DataResult(data);
    }

    /**
     * 自定义 返回操作 data 可控
     *
     * @param code
     * @param msg
     * @param data
     * @return com.xh.lesson.utils.DataResult
     * @throws
     * @Author: wujiangbo
     * @CreateDate: 2019/9/4 23:15
     * @UpdateUser:
     * @UpdateDate: 2019/9/4 23:15
     * @Version: 0.0.1
     */
    public static <T> DataResult getResult(int code, String msg, T data) {
        return new <T>DataResult(code, msg, data);
    }

    /**
     * 自定义返回  data为null
     *
     * @param code
     * @param msg
     * @return com.xh.lesson.utils.DataResult
     * @throws
     * @Author: wujiangbo
     * @CreateDate: 2019/9/4 23:15
     * @UpdateUser:
     * @UpdateDate: 2019/9/4 23:15
     * @Version: 0.0.1
     */
    public static <T> DataResult getResult(int code, String msg) {
        return new <T>DataResult(code, msg);
    }

    /**
     * 自定义返回 入参一般是异常code枚举 data为空
     *
     * @param responseCode
     * @return com.xh.lesson.utils.DataResult
     * @throws
     * @Author: wujiangbo
     * @CreateDate: 2019/9/4 23:16
     * @UpdateUser:
     * @UpdateDate: 2019/9/4 23:16
     * @Version: 0.0.1
     */
    public static <T> DataResult getResult(BaseResponseCode responseCode) {
        return new <T>DataResult(responseCode);
    }

    /**
     * 自定义返回 入参一般是异常code枚举 data 可控
     *
     * @param responseCode
     * @param data
     * @return com.xh.lesson.utils.DataResult
     * @throws
     * @Author: wujiangbo
     * @CreateDate: 2019/9/4 23:16
     * @UpdateUser:
     * @UpdateDate: 2019/9/4 23:16
     * @Version: 0.0.1
     */
    public static <T> DataResult getResult(BaseResponseCode responseCode, T data) {
        return new <T>DataResult(responseCode, data);
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
